function addRow(){
    const table = document.getElementById('datatable') as HTMLTableElement;

    const passwordtext = (<HTMLInputElement>document.getElementById('passwordtext')).value;

    if(passwordtext != '')
    {
        const newRow = table.insertRow(-1);
        const newCell1 = newRow.insertCell(0);
        const newCell2 = newRow.insertCell(1);
        const newCell3 = newRow.insertCell(2);
        var trCnt = document.getElementsByTagName('tr').length;
        trCnt = trCnt - 1;
        console.log(trCnt);
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var day = date.getDate();
        newCell1.innerText = month + "/" + day + "/" + year;
        newCell2.innerText = passwordtext;
        newCell3.innerHTML = '<td><button class="w-btn-indigo" id="'+trCnt+'" type="button" value="deldata" onclick="delRow(id)">del</button></td>';
        newRow.id = "tr"+trCnt;
    }
    else
    {
        alert('Enter the book name');
    }
} 

function update(){
    var trCnt = document.getElementsByTagName('tr').length;
    var allbook = document.getElementById('allbook') as HTMLInputElement;
    console.log(allbook);
    trCnt = trCnt - 1;
    allbook.setAttribute('value','Student name is John He has '+trCnt+' books');
}

function delRow(rownum) {
    console.log(rownum);
    (<HTMLElement>document.getElementById("tr"+rownum)).outerHTML="";
    update();
}